package com.yogurt.edu.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yogurt.edu.entity.Course;
import com.yogurt.edu.entity.Teacher;
import com.yogurt.edu.service.CourseService;
import com.yogurt.edu.service.SubjectService;
import com.yogurt.edu.service.TeacherService;
import com.yogurt.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: 酸奶
 * @Date: 2020/12/13 16:31
 * @Description: 首页面查询的控制器
 */
@RestController
@RequestMapping("/eduservice/indexfront")
@CrossOrigin
public class IndexFrontController {

    @Autowired
    private CourseService courseService;

    @Autowired
    private TeacherService teacherService;

    @ApiOperation("查询前8条课程和前4条讲师")
    @GetMapping("/index")
    public Result index(){
        //查询前8条课程
        QueryWrapper<Course> courseWrapper = new QueryWrapper<>();
        courseWrapper.orderByDesc("id");
        courseWrapper.last("limit 8");
        List<Course> courseList = courseService.list(courseWrapper);

        //查询前4条讲师
        QueryWrapper<Teacher> teacherWrapper = new QueryWrapper<>();
        teacherWrapper.orderByDesc("id");
        teacherWrapper.last("limit 4");
        List<Teacher> teacherList = teacherService.list(teacherWrapper);

        return Result.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
